<template>
  <div class="commentitems">
    <div class="commentItem" v-for="(item, index) in commentChild" :key="index">
      <div class="userImg">
        <img
          :src="baseUrl + item.handUrl"
          alt
        
          style="cursor: pointer"
        />

        <p>
          <span>{{ item.uname }}</span>

          <span>{{ item.time }}</span>
        </p>
      </div>
      <div class="commentContent">
        <div>
          <span v-if="paId != item.parentId ">
            回复 <span style="color: #478ef0">@{{ item.pname }}</span></span
          >
          {{ item.content }}
          <span
          v-if=" !isAdmin"
            class="publish"
            @click="PostItemcomment(item.id)"
            style="cursor: pointer"
            >回复</span
          >

          <span class="delCh" @click="delCh(item.id)" style="cursor: pointer"
          v-if="upId == user.id"
          >删除</span
          >

          <span class="delCh" 
          v-if="isAdmin"  
          >id:{{  item.id }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import { mapGetters } from "vuex";
export default {
  name: "commentchildItem",
  props: ["commentChild", "paId", "upId"],

  data() {
    return {
   

    };
  },
  computed: {
    ...mapGetters(["baseUrl","isLogin","isAdmin","user"]),
  },
  methods: {
    PostItemcomment(cid) {
   
      this.$emit("PostPublish", cid);
    },

    // 删除
    async delCh(cid) {
      const { data: res } = await this.$http.get("/comments/del/" + cid);
      if (res.code == 200) {
        this.$msg.fail("删除成功");
      }
      
    },



  },


};
</script>

<style lang="less" scoped>
.commentitems {
  .commentItem {
    margin-top: 1vw;
    display: flex;
    flex-direction: column;
    .userImg {
      display: flex;
      img {
        height: 2.5vw !important;
        width: 2.5vw !important;
        border-radius: 50%;
      }
      p {
        flex: 1;
        font-size: 0.88vw !important;
        color: #555;
        display: flex;
        height: 1.5vw;
        line-height: 1.5vw;
        transform: translate(1.5vw, -0.7vw);
        span:nth-child(2) {
          margin-left: 3vw;
        }
      }
    }
    .commentContent {
      margin-left: 4.3vw;
      margin-top: -1vw;
      height: 1.5vw;
      width: 80%;
      
      div {
        font-size: 1.1vw !important;
      }
      .publish {
        font-size: 0.88vw;
        margin-left: 2vw;
        color: rgb(148, 153, 181);
      }
      .delCh {
        font-size: 0.88vw;
        margin-left: 1vw;
        color: rgb(201, 22, 52);
      }
    }
  }
}
</style>